import 'package:flutter/material.dart';
import 'package:merchants/constants/agreement_content.dart';
import 'package:url_launcher/url_launcher.dart';

class AgreementViewScreen extends StatelessWidget {
  final String type; // 'user' 或 'privacy'

  const AgreementViewScreen({super.key, required this.type});

  @override
  Widget build(BuildContext context) {
    final isUserAgreement = type == 'user';
    final title = isUserAgreement ? '多赚薅省服务协议' : '多赚薅省隐私政策';
    final content =
        isUserAgreement
            ? AgreementContent.userAgreement
            : AgreementContent.privacyPolicy;
    final url =
        isUserAgreement
            ? 'https://www.shopthrive.cn/terms'
            : 'https://www.shopthrive.cn/privacy';
    final buttonText = isUserAgreement ? '查看完整服务协议' : '查看完整隐私政策';

    return Scaffold(
      appBar: AppBar(
        title: Text(
          title,
          style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
        ),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              isUserAgreement
                  ? '请仔细阅读以下服务协议，了解我们的服务条款和您的权利义务。'
                  : '请仔细阅读以下隐私政策，了解我们如何保护您的个人信息。',
              style: const TextStyle(fontSize: 14, color: Colors.grey),
            ),
            const SizedBox(height: 16),
            _buildSectionTitle(title),
            _buildSectionContent(content),
            const SizedBox(height: 16),
            TextButton(
              onPressed: () => launchUrl(Uri.parse(url)),
              child: Text(
                buttonText,
                style: const TextStyle(color: Colors.blue, fontSize: 16),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildSectionTitle(String text) {
    return Padding(
      padding: const EdgeInsets.only(top: 16, bottom: 8),
      child: Text(
        text,
        style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget _buildSectionContent(String text) {
    return Text(text, style: const TextStyle(fontSize: 16, height: 1.5));
  }
}
